package main.Q601_700;

import java.util.Arrays;

public class Q621_630 {
    public static void main(String[] args) {
        System.out.println("Question621：任务调度器");
        System.out.println("Question622：设计循环队列");
        System.out.println("Question623：");
        System.out.println("Question624：");
        System.out.println("Question625：");
        System.out.println("Question626：");
        System.out.println("Question627：");
        System.out.println("Question628：三个数的最大乘积");
        System.out.println("Question629：");
        System.out.println("Question630：");
    }
}

class Question621{
    public int leastInterval(char[] tasks, int n) {
        int[] counts = new int[26];
        for (char c : tasks) counts[c - 'A']++;
        int max = 0, tot = 0;
        for (int i = 0; i < 26; i++) max = Math.max(max, counts[i]);
        for (int i = 0; i < 26; i++) tot += max == counts[i] ? 1 : 0;
        return Math.max(tasks.length, (n + 1) * (max - 1) + tot);
    }
}

class Question622{
    int[] MyQueue;//队列
    int front,rear,capacity;//队首、队尾、容量
    public Question622(int k) {
        MyQueue=new int[k+1];
        front=0;
        rear=0;
        capacity=k+1;
    }

    public boolean enQueue(int value) {
        if (isFull()) return false;//队满
        MyQueue[rear]=value;
        rear=(rear+1)%capacity;//循环加入
        return true;
    }

    public boolean deQueue() {
        if (isEmpty()) return false;//队空
        front=(front+1)%capacity;
        return true;
    }

    public int Front() {
        if (isEmpty()) return -1;//队空
        return MyQueue[front];
    }

    public int Rear() {
        if (isEmpty()) return -1;//队空
        return MyQueue[(rear-1+capacity)%capacity];
    }

    public boolean isEmpty() {
        return rear==front;
    }

    public boolean isFull() {
        return ((rear+1)%capacity)==front;
    }
}

class Question628{
    public int maximumProduct(int[] nums) {//先排序再二分并递归
        Arrays.sort(nums);
        int n= nums.length;
        return Math.max(nums[0]*nums[1]*nums[n-1],nums[n-1]*nums[n-2]*nums[n-3]);
    }
}